﻿using Serilog;
using System.Reflection.Metadata.Ecma335;
using WorkFlowDemo.Steps;
using WorkflowFramework;

namespace WorkFlowDemo.Flows
{
    public class MyBranchWorkFlow : WorkFlowBase
    {
        public override string Name => typeof(MyBranchWorkFlow).Name;

        public override void Build(IWorkFlowBuilder builder)
        {
            Executor = builder
               .AddStep(new Step2())
               .Branch(condition: () => 1 == 1,
                trueBranch: builder => builder
                    .AddStep("Custom Step1", async () =>
                    {
                        Log.Information("Taking alternative path step 1");
                        await Task.Delay(300);
                        return FlowStepResult.Success();
                    })
                    .AddStep("Custom Step2", async () =>
                    {
                        Log.Information("Taking alternative path step 2");
                        await Task.Delay(400);
                        throw new Exception("执行失败");
                        return FlowStepResult.Success();
                    }),
                falseBranch: builder => builder
                    .AddStep("Custom Step3", async () =>
                    {
                        Log.Information("Taking normal path");
                        await Task.Delay(500);
                        return FlowStepResult.Success();
                    }))
               .AddStep(new Step3())
               .Build();
        }
    }
}
